package com.z.redis.command.impl;

import com.z.redis.RedisCore;
import com.z.redis.command.Command;
import com.z.redis.command.CommandType;
import com.z.redis.resp.BulkString;
import com.z.redis.resp.Resp;
import com.z.redis.resp.SimpleString;
import io.netty.channel.ChannelHandlerContext;

/**
 * 密码解析 (验证用户信息)
 */
public class Auth implements Command {
    //TODO 只是解析了密码 没有验证
    private String password;

    @Override
    public CommandType type(){
        return CommandType.auth;
    }

    @Override
    public void setContent(Resp[] array){
        BulkString bulkString = (BulkString) array[1];
        byte[] content = bulkString.getContent().getByteArray();
        if(content.length == 0){
            password = "";
        }else{
            password = new String(content);
        }
    }

    @Override
    public void handle(ChannelHandlerContext ctx, RedisCore redisCore){
        ctx.writeAndFlush(SimpleString.OK);
    }
}
